<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ include file="/WEB-INF/jsps/tag.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>系统数据字典明细</title>
<%@ include file="/WEB-INF/jsps/common_css.jsp"%>
<%@ include file="/WEB-INF/jsps/common_js.jsp"%>

<script type="text/javascript">

$(function(){
	
	$('#dictionaryDetail_list_id').datagrid({    
	    url:'${baseurl}dictionaryDetail/list',
	    toolbar:"#dictionaryDetail_toolbar_id",
	    pageSize:15,
	    sortName:"id",
	    sortOrder:"asc",
	    pageList:[15,30,45]
	});
	
	
	//新增
	$("#dictionaryDetail_add_id").click(function(){
		$('#dictionaryTypeSn').combobox('reload');      
		$("#dictionaryDetail_edit_id").dialog("open");
	});
	
	//取消
	$("#dictionaryDetail_edit_dialog_buttons_cancel_id").click(function(){
		$("#dictionaryDetail_edit_id").dialog("close");
		$('#dictionaryDetail_form_id').form("clear");
	});
	

 	//提交表单
	$("#dictionaryDetail_edit_dialog_buttons_ok_id").click(function(){
		if(!$('#dictionaryDetail_form_id').form("validate")){
			return;
		}
		
		var id = $("#id").val();
		var name = $("#dictionaryDetail_name_id").val();
		var typeId = $("#dictionaryTypeSn").combobox("getValue");
// 		alert("id===>"+id+"    name===>"+name+"   typeId===>"+typeId);
		
		$.post("${baseurl}dictionaryDetail/saveOrUpdate", { "id":id,"name":name,"types.id":typeId},
			 function(data){
			  if(data.success){
		        	$('#dictionaryDetail_list_id').datagrid("reload");
		        	$.messager.show({title:'系统提示',msg:data.content,timeout:5000,showType:'slide'});
		        }
			    $("#dictionaryDetail_edit_id").dialog("close");
			    $('#dictionaryDetail_form_id').form("clear");
			    $.messager.show({title:'操作失败',msg:data.content,timeout:5000,showType:'slide'});
			  }
			 ,"json"); 
	});
	
	
	//删除
	$("#dictionaryDetail_delete_id").click(function(){
		var selected =  $("#dictionaryDetail_list_id").datagrid("getSelected");
		if(selected == null){
			alert("请选中你要删除的记录.");
		}else{
			$.post("${baseurl}dictionaryDetail/delete", { "id":selected.id},
					   function(data){
					    	if(data.success){
					    		$('#dictionaryDetail_list_id').datagrid("reload");
					    		$.messager.show({title:'系统提示',msg:data.content,timeout:5000,showType:'slide'});
					    	}else{
					    		$('#dictionaryDetail_form_id').form("clear");
					    		$.messager.alert('警告',data.content); 
					    	}
					   }, "json");
		}
	});
	
	
	//修改
	$("#dictionaryDetail_update_id").click(function(){
		var selected =  $("#dictionaryDetail_list_id").datagrid("getSelected");
		if(selected == null){
			alert("请选中你要修改的记录.");
		}else{
			$('#dictionaryDetail_form_id').form("load",selected);
			$('#dictionaryTypeSn').combobox('reload');
			$("#dictionaryTypeSn").combobox("select",selected.types.id);
			$("#dictionaryDetail_edit_id").dialog("open");
		}
	});
	
	
	//高级查询
	$("#dictionaryDetail_query_button_id").click(function(){
		var typesSn = $("#dictionaryType_query_types_id").combobox("getValue");
		var name = $("#dictionaryDetail_query_name_id").val();
		if(name!=null && name!=""){
			name = name.trim();
		}
		$('#dictionaryDetail_list_id').datagrid("reload",{name:name,typesSn:typesSn});
	});
	
	
});
	
</script>
</head>
<body>

	<!-- 搜索栏 -->
	<div style="height: 30px;width: 100%;border: 1px solid #BCB7B7;margin-top: 0px;">
		<table>
			<tr>
				<th>名称:</th>
				<td> <input id="dictionaryDetail_query_name_id" class="easyui-textbox" type="text" name="name" data-options="" />  <td>
				<th>类型:</th>
				<td>  <input id="dictionaryType_query_types_id" class="easyui-combobox" name="types.id"   
    								data-options="valueField:'sn',textField:'name',url:'${baseurl}dictionaryType/all',editable:false" />  
    			<td>
    			<td>
    				<a id="dictionaryDetail_query_button_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-2012092109942'">过滤</a>  
    			</td>
			</tr>
		</table>
	</div>
	
	<!-- 数据表格 -->
	<table id="dictionaryDetail_list_id" style="width:100%;height:94%;"
		data-options="fitColumns:true,singleSelect:true,pagination:true,pagePosition:'bottom'">   
	    <thead>   
	        <tr>   
	            <th data-options="field:'id',width:20,order:'asc',sortable:true">id</th>   
	            <th data-options="field:'name',width:20">名称</th>
              	<th data-options="field:'types',width:20,formatter:function(value,row,index){
              			return value.name+'/'+value.sn;
              		}">类型/字典编号</th>
	        </tr>   
	    </thead>   
	</table>
	
	<!-- 数据表格toolbar -->
	<div id="dictionaryDetail_toolbar_id">
		<a id="dictionaryDetail_add_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">新增 </a>
		<a id="dictionaryDetail_update_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a>
		<a id="dictionaryDetail_delete_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
	</div>
	
	<!-- 编辑对话框 -->
	<div id="dictionaryDetail_edit_id" class="easyui-dialog" title="字典详情管理" style="width:300px;height:150px"   
        data-options="iconCls:'icon-save',modal:true,closed:true,buttons:'#dictionaryDetail_edit_dialog_buttons_id'">   
   		<form id="dictionaryDetail_form_id" method="post">
   			<input  id="id"  type="hidden" name="id"/>
   			<table>
   				<tr>
   					<td>
   						<div>   
					        <label for="dictionaryDetailname">名称:</label>   
					        <input id="dictionaryDetail_name_id" class="easyui-validatebox" type="text" name="name" data-options="required:true" />
					    </div> 
   					</td>
   				</tr>
   				<tr>
   					<td>
   						<div>   
					        <label for="dictionaryDetailname">类型:</label>   
					          <input id="dictionaryTypeSn" class="easyui-combobox" name="types.id"   
    								data-options="valueField:'id',textField:'name',url:'${baseurl}dictionaryType/all',editable:false,required:true" />  
					    </div> 
   					</td>
   				</tr>
   			</table>
		</form>
	</div>
	
	<!-- 编辑对话框的buttons -->
	<div id="dictionaryDetail_edit_dialog_buttons_id">
		<a id="dictionaryDetail_edit_dialog_buttons_ok_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">保存</a>
		<a id="dictionaryDetail_edit_dialog_buttons_cancel_id" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">关闭</a>
	</div>
</body>
</html>